package com.sumanning.mylibmanger.utils;

//继承SQLiteOpenHelper类

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class SqliteHelper extends SQLiteOpenHelper {

    //定义变量
    private static final String DATABASE_NAME = "book.db";
    private static final int VERSION = 1;

    //构造方法，参数一：上下文，参数二：数据库名，参数三：游标工厂，参数四：版本号
    public SqliteHelper(Context context) {
        super(context, DATABASE_NAME, null, VERSION);
    }
    //创建sql语句和初始化，重点：创建id必须为_id形式
    public void onCreate(SQLiteDatabase db) {
        String sql = "create table t_book(_id integer primary key autoincrement,name text,price integer)" +
                "insert into t_book values(1,\"java开发经典\",22);\n" +
                "insert into t_book values(1,\"Android开发经典\",45);\n" +
                "insert into t_book values(1,\"python开发经典1\",12);\n" +
                "insert into t_book values(1,\"VB开发经典2\",22);\n" +
                "insert into t_book values(1,\"C++开发经典3\",45);\n" +
                "insert into t_book values(1,\"Spring开发经典4\",56);\n" +
                "insert into t_book values(1,\"SSH开发经典5\",34);\n" +
                "insert into t_book values(1,\"SSM开发经典6\",23);";
        //执行sql语句
        db.execSQL(sql);

    }
    //版本更新
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
